package com.yxc.elasticsearchdemo;

import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;

/**
 * @author: 杨旭晨
 * @time: 2022/6/22 19:06
 **/
@SpringBootTest
public class DeleteDataFromEs {

    @Autowired
    RestHighLevelClient client;

    @Test
    void deleteDemo() throws IOException {
        DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest("ceshi");
        deleteByQueryRequest.setQuery(new MatchQueryBuilder("cName.keyword", "更新测试1000000"));
        deleteByQueryRequest.setRefresh(true);
        BulkByScrollResponse bulkByScrollResponse = client.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT);
        System.out.println(bulkByScrollResponse);
    }

}
